﻿<%@ Page Title="" Language="C#" MasterPageFile="~/Main.Master" AutoEventWireup="true"
    CodeBehind="Create.aspx.cs" Inherits="VirtualOrg.Web.FormCreateUser" %>

<asp:Content ID="Content1" ContentPlaceHolderID="MainContent" runat="server">
    <script type="text/javascript">
        $(function () {
            $("#MainContent_txtBirthday").datepicker({
                changeMonth: true,
                changeYear: true
            });
        });

        $(function () {
            $("#accordion").accordion();
        });

        function CreateUser() {
            if (jQuery('#form1').validationEngine('validate') == true) {
                var name = document.getElementById('<%=txtName.ClientID %>').value;
                var emailID = document.getElementById('<%=txtEmail.ClientID %>').value;
                var birthday = document.getElementById('<%=txtBirthday.ClientID %>').value;
                var sex = document.getElementById('<%=ddlSex.ClientID %>').value;
                var country = document.getElementById('<%=ddlCountry.ClientID %>').value;
                var location = document.getElementById('<%=txtLocation.ClientID %>').value;
                var username = document.getElementById('<%=txtUsername.ClientID %>').value;
                var password = document.getElementById('<%=txtPassword.ClientID %>').value;

                ob_post.AddParam("name", name);
                ob_post.AddParam("emailID", emailID);
                ob_post.AddParam("birthday", birthday);
                ob_post.AddParam("sex", sex);
                ob_post.AddParam("country", country);
                ob_post.AddParam("location", location);
                ob_post.AddParam("username", username);
                ob_post.AddParam("password", password);

                ob_post.post(null, "CreateUser", CreateUserResponse);
            }

            return false;
        }

        function CreateUserResponse(result) {
            msgboxpanel.innerHTML = result;
        }

        function CheckUsername() {
            var username = document.getElementById('<%=txtUsername.ClientID %>').value;
            ob_post.AddParam("searchText", username);

            ob_post.post(null, "CheckUsername", CheckUsernameResponse);
        }

        function CheckUsernameResponse(result) {
            var username = document.getElementById('<%=txtUsername.ClientID %>').value;
            if (result) {
                spanUsernameCheck.innerText = "'" + username + "' is available";
                spanUsernameCheck.style.color = "Green";
            }
            else {
                spanUsernameCheck.innerText = "'" + username + "' is not available";
                spanUsernameCheck.style.color = "Red";
            }
        }

        function CheckEmail() {
            var emailID = document.getElementById('<%=txtEmail.ClientID %>').value;
            ob_post.AddParam("searchText", emailID);

            ob_post.post(null, "CheckEmail", CheckUseremailResponse);
        }

        function CheckUseremailResponse(result) {
            if (!result) {
                spanEmailExist.innerText = "Email already registered";
                spanEmailExist.style.color = "Red";
            }
            else {
                spanEmailExist.innerText = "";
            }
        }
    </script>
    <h2>
        Create an account</h2>
    <hr />
    <div id="accordion" style="width: 100%;">
        <h3>
            <a href="#">Enter the details to create an account</a></h3>
        <div>
            <table style="width: 100%; height: 320px; width: 650px;">
                <tr>
                    <td>
                        <label for="author">
                            Username:</label>
                    </td>
                    <td colspan="3">
                        <asp:TextBox ID="txtUsername" runat="server" onchange="CheckUsername();" CssClass="validate[required,minSize[6]] input_field ui-corner-all"></asp:TextBox>
                        &nbsp;&nbsp;&nbsp; <span id="spanUsernameCheck" style="font-weight: bold; font-size: 11px;">
                        </span>
                    </td>
                </tr>
                <tr>
                    <td>
                        <label>
                            Password:</label>
                    </td>
                    <td>
                        <asp:TextBox ID="txtPassword" TextMode="Password" runat="server" CssClass="validate[required,minSize[6]] input_field ui-corner-all"></asp:TextBox>
                    </td>
                    <td>
                        <label style="width: 200px;">
                            Password again:</label>
                    </td>
                    <td>
                        <asp:TextBox ID="txtPasswordAgain" TextMode="Password" runat="server" CssClass="validate[required,equals[MainContent_txtPassword]] input_field ui-corner-all"></asp:TextBox>
                    </td>
                </tr>
                <tr>
                    <td>
                        &nbsp;
                    </td>
                    <td>
                        &nbsp;
                    </td>
                </tr>
                <tr>
                    <td>
                        <span class="spancls">Name:</span>
                    </td>
                    <td>
                        <asp:TextBox ID="txtName" runat="server" CssClass="validate[required] input_field ui-corner-all"></asp:TextBox>
                    </td>
                    <td>
                        <label for="email">
                            Email:</label>
                    </td>
                    <td>
                        <asp:TextBox ID="txtEmail" runat="server" onchange="CheckEmail();" CssClass="validate[required,custom[email]] input_field ui-corner-all"></asp:TextBox><br />
                        <span id="spanEmailExist" style="font-weight: bold; font-size: 11px;"></span>
                    </td>
                </tr>
                <tr>
                    <td>
                        <label for="author">
                            Birthday:</label>
                    </td>
                    <td>
                        <asp:TextBox ID="txtBirthday" runat="server" ReadOnly="true" CssClass="validate[required] input_field ui-corner-all"></asp:TextBox>
                    </td>
                    <td>
                        <label for="email">
                            Sex:</label>
                    </td>
                    <td>
                        <asp:DropDownList ID="ddlSex" CssClass="validate[required] select_field ui-corner-all"
                            runat="server">
                            <asp:ListItem></asp:ListItem>
                            <asp:ListItem>Male</asp:ListItem>
                            <asp:ListItem>Female</asp:ListItem>
                        </asp:DropDownList>
                    </td>
                </tr>
                <tr>
                    <td>
                        <label for="author">
                            Country:</label>
                    </td>
                    <td>
                        <asp:DropDownList ID="ddlCountry" CssClass="validate[required] select_field ui-corner-all"
                            runat="server">
                            <asp:ListItem></asp:ListItem>
                            <asp:ListItem>India</asp:ListItem>
                            <asp:ListItem>China</asp:ListItem>
                        </asp:DropDownList>
                    </td>
                    <td>
                        <label for="email">
                            Location:</label>
                    </td>
                    <td>
                        <asp:TextBox ID="txtLocation" runat="server" CssClass="input_field ui-corner-all"></asp:TextBox>
                    </td>
                </tr>
                <tr>
                    <td colspan="2">
                        <asp:CheckBox ID="chkTermsCondition" runat="server" />
                        I agree with the <a href="../TermsCondition.aspx" class="link">Terms & Conditions</a>
                    </td>
                </tr>
                <tr>
                    <td colspan="4">
                        <asp:Button ID="btnCreate" OnClientClick="return CreateUser();" runat="server" Text="Create an account" />
                        <asp:Button ID="btnLogin" runat="server" Text="Go to login page" />
                    </td>
                </tr>
            </table>
        </div>
        </div>
</asp:Content>
